package com.dawn.usermanage.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.dawn.usermanage.bean.UserBean;

@Repository
public class UserManageDao {

	@Autowired
	private HibernateTemplate hibernateTemplate;

	public UserBean findUserByUid(long userId) {
		UserBean user = (UserBean) hibernateTemplate.get(UserBean.class, userId);
		return user;
	}

	public List<UserBean> findUserByUName(String userName) {
		@SuppressWarnings("unchecked")
		List<UserBean> users = (List<UserBean>) hibernateTemplate.find("from UserBean u where u.userName = ?", userName);
		return users;
	}

	public List<UserBean> findUserBySId(String sinaId) {
		@SuppressWarnings("unchecked")
		List<UserBean> users = (List<UserBean>) hibernateTemplate.find("from UserBean u where u.sinaInfoBean.sinaId = ?", sinaId);
		return users;
	}

	public void addUser(UserBean userBean) {
		hibernateTemplate.save(userBean);
	}
	
	public void uppdateUser(UserBean userBean){
		hibernateTemplate.update(userBean);
	}

}
